/*
 * Copyright (C) 2012 Rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.server.packets;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import rpg.server.net.NetworkHandler;

/**
 * rothens.tumblr.com
 * @author Rothens
 */
public class Packet1Login extends Packet {

	public String username;
	public int version;

	public Packet1Login() {
	}

	public Packet1Login(String username, int version) {
		this.username = username;
		this.version = version;
	}

	@Override
	public void readPacketData(DataInputStream dis) throws IOException {
		version = dis.readInt();
		username = readString(dis, 32);
	}

	@Override
	public void writePacketData(DataOutputStream dos) throws IOException {
		dos.writeInt(version);
		writeString(username, dos);
	}

	@Override
	public int getSize() {
		return username.length() + 4;
	}

	@Override
	public void processPacketData(NetworkHandler h) {
		h.handleLogin(this);
	}
}
